home *** CD-ROM | disk | FTP | other *** search
/ Exame Informatica 140 / Exame Informatica 140.iso / Revista / Flash / codigo.as < prev    next >
Encoding:
Text File  |  2006-12-19  |  2.7 KB  |  100 lines

  1. ∩╗┐var speed:Number = 0; 
  2. var maxMove:Number = 15; 
  3. var jumpSpeed:Number = -10;
  4. var totalMapas:Number = 6;
  5. var mapaActual:Number = 2;
  6. var mapaActual2:Number = 2;
  7. var charEscala:Number = 25;
  8. var wall:String = "";
  9. var jumping:Boolean = true;
  10. var falling:Boolean = true;
  11.  
  12. function inicializarJogo():Void{
  13.     _root.createEmptyMovieClip("fundo2",_root.getNextHighestDepth());
  14.     _root.createEmptyMovieClip("fundo",_root.getNextHighestDepth());
  15.     _root.fundo2.attachMovie("fundoLonginquo","fundoLonginquo1",fundo2.getNextHighestDepth());
  16.     _root.fundo2.attachMovie("fundoLonginquo","fundoLonginquo2",fundo2.getNextHighestDepth());
  17.     _root.fundo.attachMovie("chao","chao1",fundo.getNextHighestDepth());
  18.     _root.fundo.attachMovie("chao","chao2",fundo.getNextHighestDepth());
  19.     _root.attachMovie("char","char",_root.getNextHighestDepth());
  20.     _root.fundo.cacheAsBitmap = true;
  21.     _root.fundo2.cacheAsBitmap = true;
  22.     _root.char.cacheAsBitmap = true;
  23.     _root.fundo.chao1.gotoAndStop(1);
  24.     _root.fundo.chao2.gotoAndStop(2);
  25.     _root.fundo2.fundoLonginquo1.gotoAndStop(1);
  26.     _root.fundo2.fundoLonginquo2.gotoAndStop(2);
  27.     _root.fundo2._x = 0;
  28.     _root.fundo2._y = 0;
  29.     _root.fundo._x = 0;
  30.     _root.fundo._y = Stage.height;
  31.     _root.fundo2.fundoLonginquo1._x = 0;
  32.     _root.fundo2.fundoLonginquo1._y = 0;
  33.     _root.fundo2.fundoLonginquo2._x = _root.fundo2.fundoLonginquo1._width;
  34.     _root.fundo2.fundoLonginquo2._y = 0;
  35.     _root.fundo.chao1._x = 0;
  36.     _root.fundo.chao1._y = 0;
  37.     _root.fundo.chao2._x = fundo.chao1._width;
  38.     _root.fundo.chao2._y = 0;
  39.     _root.char._xscale = char._yscale = charEscala;
  40.     _root.char._x = Stage.width/2;
  41.     _root.char._y = Stage.height/2;
  42.     
  43.     }
  44. function detectarTeclas():Void{
  45.     //atrito
  46.     speed *= .85;
  47.     if (Key.isDown(Key.LEFT) && wall != "esq") { 
  48.         wall = "";
  49.         if (speed>-maxMove) { 
  50.             speed--; 
  51.         }
  52.     } else if (Key.isDown(Key.RIGHT) && wall != "dir") { 
  53.         posicionarMapas();
  54.         wall = "";
  55.         if (speed<maxMove) { 
  56.             speed++; 
  57.         } 
  58.     }
  59.     if (Key.isDown(Key.UP) && !jumping) { 
  60.         wall = "";
  61.         jumping = true; 
  62.     }
  63. }
  64.  
  65. function moverPersonagem():Void{
  66.     var mc:MovieClip = _root.char;
  67.         if (speed>0) { 
  68.             // andar para a Direita
  69.             mc.play();
  70.             mc._xscale = charEscala;
  71.             if(mc._x < Stage.width/2){
  72.                 mc._x += speed; 
  73.             }else{
  74.                 mc._x += speed/50; 
  75.                 fundo2._x -= speed/10;
  76.                 fundo._x -= speed; 
  77.             }
  78.         } else if (speed<0) { 
  79.             // andar para a Esquerda    
  80.             if(mc._x <=0){
  81.                 mc._x = 0;
  82.             }else{
  83.                 mc.play();
  84.                 mc._xscale = -charEscala;
  85.                 mc._x += speed;
  86.             }    
  87.         }
  88.     if (speed<1 && speed>-1) { 
  89.             // parado    
  90.             speed = 0; 
  91.             mc.gotoAndStop(1); 
  92.     }     
  93. }
  94.  
  95. inicializarJogo();
  96.  
  97. onEnterFrame = function(){
  98.     detectarTeclas();
  99.     moverPersonagem();
  100.     }